let userInfo = function(key, cookie_name='info') {
    try {
        let res = JSON.parse(new Base64().decode(Cookies.get(cookie_name)));
        return key?res[key]: res;
    }catch(e) {
        return '';
    }
};

let site_config_data = {};
let getSiteConfigCallbacks = [];
let is_loading_data = false;
let getSiteConfig = function(key, callback=()=>{}, reload = false) {
    if(is_loading_data && callback) {
        getSiteConfigCallbacks.push({key:key, callback:callback});
        return;
    }
    if(reload || !site_config_data) {
        getSiteConfigCallbacks.push({key:key, callback:callback})
        is_loading_data = true;
        Vue.prototype.$axios.get('/company/getInfo').then(res => {
            if(res.s == 1) {
                let data = res.d;
                if(data) {
                    site_config_data = data;
                }
            }
        }).finally(() => {
            is_loading_data = false;
            getSiteConfigCallbacks.forEach(val => {
                val.callback((val.key && site_config_data ? site_config_data[val.key]:site_config_data)||'');
            })
        })
    }else {
        callback((key ? site_config_data[key]:site_config_data)||'');
    }
};
let lightColor = function(color, percent) {
    var f = parseInt(color.slice(1),16);
    var t = percent < 0 ? 0 : 255;
    var p = percent < 0 ? percent * -1 : percent;
    var R = f >> 16;
    var G = f >> 8 & 0x00FF, B = f & 0x0000FF;
    return "#"+(0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1);
};